﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace GameUtils
{
    public struct PolarVector2
    {
        #region Properties
        #region Magnitude
        /// <summary>
        /// Magnitude property.
        /// </summary>
        public float Magnitude;
        #endregion

        #region Direction
        private float mDirection;

        /// <summary>
        /// Direction property.
        /// </summary>
        public float Direction
        {
            get { return mDirection; }
            set
            {
                mDirection = MathUtils.WrapAngleRad(value);
            }
        }
        #endregion

        #region X
        /// <summary>
        /// X property.
        /// </summary>
        public float X
        {
            get { return (float)(Magnitude * Math.Cos(Direction)); }
        }
        #endregion

        #region Y
        /// <summary>
        /// Y property.
        /// </summary>
        public float Y
        {
            get { return (float)(Magnitude * Math.Sin(Direction)); }
        }
        #endregion
        #endregion

        #region Constructors
        public PolarVector2(
            float pMagnitude,
            float pDirection)
        {
            Magnitude = pMagnitude;
            mDirection = pDirection;

            Direction = pDirection;
        }
        #endregion

        #region Methods
        public void NegateX()
        {
            Direction = -(Direction + MathHelper.PiOver2) - MathHelper.PiOver2;
        }

        public void NegateY()
        {
            Direction = -Direction;
        }

        public Vector2 ToVector2()
        {
            return new Vector2(X, Y);
        }
        #endregion
    }
}